//
//  RCRecommendFoodDataModel.m
//  RocketProject
//
//  Created by chen jiedan on 13-6-25.
//  Copyright (c) 2013年 Rocket. All rights reserved.
//

#import "RCRecommendFoodDataModel.h"
#import "FrameworkRelativeDefines.h"

@implementation RCRecommendFoodListDataModel


// 将JSON数据解析为数据模型
-(id) parseDataFromJSON:(NSDictionary*)data
{
    // 输入参数判断
    if ( nil == data )
        return nil;
    
    // 分配数据模型对象内存
    RCRecommendFoodListDataModel *retObject = nil;
    retObject = [[RCRecommendFoodListDataModel alloc] init];
    if ( nil == retObject )
        return retObject;
    
    retObject.err = [[[ServerError alloc] initWithDic:data] autorelease];
    
    NSMutableArray *listItems = [[NSMutableArray alloc] init];
    
    NSDictionary *dataDic = [data dictionaryValueForKey:@"data" defaultValue:nil];
    retObject.pn     = [dataDic intValueForKey:@"pn" defaultValue:0];
    retObject.rn     = [dataDic intValueForKey:@"rn" defaultValue:0];
    retObject.total  = [dataDic intValueForKey:@"total" defaultValue:0];
    
    NSArray *dataItems = [dataDic arrayValueForKey:@"list" defaultValue:nil];
    for (NSDictionary *dic in dataItems) {
        RCRecommendFoodItemDataModel *merchant = [[RCRecommendFoodItemDataModel alloc] initWithDic:dic];
        [listItems addObject:merchant];
        [merchant release];
    }
    retObject.listItems = listItems;
    [listItems release];
    
    // 返回结果数据模型
    return [retObject autorelease];
}


@end


@implementation RCRecommendFoodItemDataModel
@synthesize foodID = _foodID;
@synthesize foodName=_foodName;
@synthesize restaurant=_restaurant;
@synthesize desc = _desc;
@synthesize picUrl = _picUrl;

- (id) initWithDic:(NSDictionary *)dic
{
    self = [super init];
    if (self) {
        self.foodName = [dic stringValueForKey:@"name" defaultValue:nil operation:NSStringOperationTypeNone];
        self.foodID = [dic stringValueForKey:@"id" defaultValue:nil operation:NSStringOperationTypeNone];
        self.restaurant = [dic stringValueForKey:@"restaurant" defaultValue:nil operation:NSStringOperationTypeNone];
        self.picUrl = [dic stringValueForKey:@"picurl" defaultValue:nil operation:NSStringOperationTypeNone];
        self.desc = [dic stringValueForKey:@"desc" defaultValue:nil operation:NSStringOperationTypeNone];

    }
    return self;
}

- (void) dealloc
{
    self.foodID = nil;
    self.foodName = nil;
    self.restaurant = nil;
    self.desc = nil;
    self.picUrl = nil;
    [super dealloc];
}

@end
